/*
 * Copyright (c) 2006-2023, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-10-18     RT-Thread    first version
 */

#include <rtthread.h>
#include <rtdevice.h>
#define DBG_TAG "main"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

rt_device_t uart5;
int main(void)
{
    int count = 1;
    int err = RT_EOK;
    uart5 = rt_device_find("uart5");
    if (uart5 == RT_NULL)
    {
        LOG_E("serial5 not found!");
    }
    else
    {
        struct serial_configure config = {
                .baud_rate = BAUD_RATE_9600,
                .bit_order = BIT_ORDER_LSB,
                .data_bits = DATA_BITS_8,
                .flowcontrol = RT_SERIAL_FLOWCONTROL_NONE,
                .parity = PARITY_NONE,
                .stop_bits = STOP_BITS_1,
        };
        err = rt_device_control(uart5, RT_DEVICE_CTRL_CONFIG, &config);
        if (err != RT_EOK)
        {
            LOG_E("configure serial5 failed! %d", err);
        }
        err = rt_device_open(uart5, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX);
        LOG_I("open serial5:%d", err);
        
    }
    while (count++ < 1000)
    {
        if (uart5)
        {

            err = rt_device_write(uart5, 0, "---hello RT-Thread23!\r\n", 24);
            if (err != 24)
            {
                LOG_E("write serial5 failed! %d",err);
            }
        }
        LOG_D("Hello RT-Thread!");
        rt_thread_mdelay(1000);
    }

    return RT_EOK;
}
